﻿using System;
using System.Reflection;
using System.Text;

namespace HslCommunication.LogNet
{
	/// <summary>
	/// 日志类的管理器，提供了基本的功能代码。<br />
	/// The manager of the log class provides the basic function code.
	/// </summary>
	// Token: 0x020000DF RID: 223
	public class LogNetManagment
	{
		// Token: 0x06001134 RID: 4404 RVA: 0x0006234C File Offset: 0x0006054C
		internal static string GetDegreeDescription(HslMessageDegree degree)
		{
			string result;
			switch (degree)
			{
			case HslMessageDegree.None:
				result = StringResources.Language.LogNetAbandon;
				break;
			case HslMessageDegree.FATAL:
				result = StringResources.Language.LogNetFatal;
				break;
			case HslMessageDegree.ERROR:
				result = StringResources.Language.LogNetError;
				break;
			case HslMessageDegree.WARN:
				result = StringResources.Language.LogNetWarn;
				break;
			case HslMessageDegree.INFO:
				result = StringResources.Language.LogNetInfo;
				break;
			case HslMessageDegree.DEBUG:
				result = StringResources.Language.LogNetDebug;
				break;
			default:
				result = StringResources.Language.LogNetAbandon;
				break;
			}
			return result;
		}

		/// <summary>
		/// 公开的一个静态变量，允许随意的设置<br />
		/// Public static variable, allowing arbitrary setting
		/// </summary>
		// Token: 0x17000268 RID: 616
		// (get) Token: 0x06001135 RID: 4405 RVA: 0x000623DC File Offset: 0x000605DC
		// (set) Token: 0x06001136 RID: 4406 RVA: 0x000623E3 File Offset: 0x000605E3
		public static ILogNet LogNet { get; set; }

		/// <summary>
		/// 通过异常文本格式化成字符串用于保存或发送<br />
		/// Formatted as a string with exception text for saving or sending
		/// </summary>
		/// <param name="text">文本消息</param>
		/// <param name="ex">异常</param>
		/// <returns>异常最终信息</returns>
		// Token: 0x06001137 RID: 4407 RVA: 0x000623EC File Offset: 0x000605EC
		public static string GetSaveStringFromException(string text, Exception ex)
		{
			StringBuilder stringBuilder = new StringBuilder(text);
			bool flag = ex != null;
			if (flag)
			{
				bool flag2 = !string.IsNullOrEmpty(text);
				if (flag2)
				{
					stringBuilder.Append(" : ");
				}
				try
				{
					stringBuilder.Append(StringResources.Language.ExceptionMessage);
					stringBuilder.Append(ex.Message);
					stringBuilder.Append(Environment.NewLine);
					stringBuilder.Append(StringResources.Language.ExceptionSource);
					stringBuilder.Append(ex.Source);
					stringBuilder.Append(Environment.NewLine);
					stringBuilder.Append(StringResources.Language.ExceptionStackTrace);
					stringBuilder.Append(ex.StackTrace);
					stringBuilder.Append(Environment.NewLine);
					stringBuilder.Append(StringResources.Language.ExceptionType);
					stringBuilder.Append(ex.GetType().ToString());
					stringBuilder.Append(Environment.NewLine);
					stringBuilder.Append(StringResources.Language.ExceptionTargetSite);
					StringBuilder stringBuilder2 = stringBuilder;
					MethodBase targetSite = ex.TargetSite;
					stringBuilder2.Append((targetSite != null) ? targetSite.ToString() : null);
				}
				catch
				{
				}
				stringBuilder.Append(Environment.NewLine);
				stringBuilder.Append("\u0002/=================================================[    Exception    ]================================================/");
			}
			return stringBuilder.ToString();
		}

		/// <summary>
		/// 日志文件的头标志
		/// </summary>
		// Token: 0x0400047C RID: 1148
		internal const string LogFileHeadString = "Logs_";
	}
}
